package indi.kider.server.applandlord.api;

import indi.kider.common.model.apabus.RentMonthReport;
import indi.kider.server.applandlord.service.related.ApaBusService;
import indi.kider.server.applandlord.service.related.BalanceBill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;
import pers.vankid.common.utils.page.PageRequest;

import java.util.List;

/**
 * Created by shixj on 2018/5/30.
 */
@RestController
@RequestMapping(value = "index", produces = "application/json;charset=UTF-8")
public class IndexCountController {
    @Autowired
    private BalanceBill balanceBill;
    @Autowired
    private ApaBusService apaBusService;

    /**
     * @api {GET} index/bill/month-count/now
     * @apiGroup app-landlord
     * @apiDescription 财务月统计
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/index/bill/month-count/now
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"phone":"18013897594","actualTotal":"累计实收","expectTotal":"累计应收","monthActualTotal":"月实收","monthExpectTotal":"月应收","countMonth":"2018/05","monthBaseActual":"月房租物业固定实收","monthBaseExpect":"月房租物业固定应收","monthReadingActual":"月水电实收","monthReadingExpect":"月水电应收"}}
     */
    @GetMapping("bill/month-count/now")
    public CommonResponse getEmployeeBillCountNowAndLast() {
        return balanceBill.getEmployeeBillCountNow();
    }

    /**
     * @api {POST} index/bill/month-count/list
     * @apiGroup app-landlord
     * @apiDescription 财务月统计
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/index/bill/month-count/list
     * {"num":"0","size":"8","query":"18013865984"}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"rows":[{"status":"200","msg":"查询成功！","data":{"phone":"18013897594","actualTotal":"累计实收","expectTotal":"累计应收","monthActualTotal":"月实收","monthExpectTotal":"月应收","countMonth":"2018/05","monthBaseActual":"月房租物业固定实收","monthBaseExpect":"月房租物业固定应收","monthReadingActual":"月水电实收","monthReadingExpect":"月水电应收"}}],"total":4,"size":2}}
     */
    @PostMapping("bill/month-count/list")
    public CommonResponse getEmployeeBillCountPage(@RequestBody PageRequest<String> request) {
        return balanceBill.getEmployeeBillCountPage(request);
    }


    /**
     * @api {GET} index/getReportNow/{phone}
     * @apiGroup app-landlord
     * @apiDescription 房源月统计
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/index/getReportNow/{phone}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":{"id":null,"enterprise":1,"total":3,"rentTotal":0,"month":"2018-05"}}
     */
    @GetMapping("/getReportNow/{phone}")
    public CommonResponse<RentMonthReport> getReportNow(@PathVariable(value = "phone") String phone) {
        return apaBusService.getReportNow(phone);
    }

    /**
     * @api {GET} index/getReportlist/{month}/{phone}
     * @apiGroup app-landlord
     * @apiDescription 时间查询租房报表
     * @apiParamExample 请求样例：
     * http://localhost:9002/app-landlord/index/getReportlist/{month}/{phone}
     * @apiSuccessExample {json} 返回样例:
     * {"status":"200","msg":"查询成功！","data":[{"id":1,"enterprise":1,"total":2,"rentTotal":0,"month":"2018-05"}]}
     */
    @GetMapping("/getReportlist/{month}/{phone}")
    public CommonResponse<List<RentMonthReport>> getReportlist(@PathVariable(value = "month") String month,
                                                               @PathVariable(value = "phone") String phone) {
        return apaBusService.getReportlist(month, phone);
    }
}
